'use strict';

const Controller = require('egg').Controller;
const fs = require("fs")
const path = require("path")
class CenterController extends Controller {
  async Per_center() {
    console.log(123321)
    const { ctx } = this;
    //获取前端发送的数据
    var ziduan = ctx.request.body;
    var f1 = ctx.request.files
    console.log(ziduan);

    //将数据存入数据库
    let sql =
      `INSERT INTO personal (username, usercard, usertel, useryx, userpwd_zf,usertx) VALUES("${ziduan.name}","${ziduan.id}","${ziduan.tel}","${ziduan.yx}","${ziduan.pwd_zf}","${ziduan.tx}")`
    console.log(56789)
    let result = await this.app.mysql.query(sql)
    console.log(result, 77);
  }

  //返回登录用户信息
  async getUser() {
    let bool = await this.ctx.service.persenal.islogin()
    if (bool) {
      let email = this.ctx.session.email
      let re1 = await this.ctx.service.per_cen.getPersonal(email)
      // console.log(ziduan);
      this.ctx.body = {
        info: "登录成功",
        code: 2002,
        ...re1[0]
      }
    } else {
      this.ctx.body = {
        info: "未登录",
        code: 4004
      }
    }
  }
}





module.exports = CenterController;
